/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:56 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{
    public class TrangslideDAL : SqlProvider<TrangslideEntity>
    {
        static TrangslideDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                TrangslideEntity entity = new TrangslideEntity();
                entity.PK_iTrangslideID = Int64.Parse("0" + dr["PK_iTrangslideID"].ToString());
                entity.FK_iSlideID = Int64.Parse("0" + dr["FK_iSlideID"].ToString());
                entity.iSothutu = short.Parse("0" + dr["iSothutu"].ToString());
                entity.sTieude = dr["sTieude"].ToString();
                entity.sGhichu = dr["sGhichu"].ToString();
                return entity;
            };
        }
        public static TrangslideEntity GetOne(Int64 PK_iTrangslideID)
        {
            string cmdName = "spTrangslide_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iTrangslideID", PK_iTrangslideID);
            TrangslideEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<TrangslideEntity> GetAll()
        {
            string cmdName = "spTrangslide_Get";
            return GetList(cmdName);
        }

        public static List<TrangslideEntity> GetByFK_iSlideID(Int64 FK_iSlideID)
        {
            string cmdName = "spTrangslide_GetByFK_iSlideID";
            SqlParameter p = new SqlParameter("@FK_iSlideID", FK_iSlideID);
            List<TrangslideEntity> lst = GetList(cmdName, p);
            return lst;
        }
        
        public static int Add(TrangslideEntity entity)
        {
            string cmdName = "spTrangslide_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(TrangslideEntity entity)
        {
            string cmdName = "spTrangslide_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iTrangslideID)
        {
            string cmdName = "spTrangslide_Delete";
            SqlParameter p = new SqlParameter("@PK_iTrangslideID", PK_iTrangslideID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(TrangslideEntity entity)
        {
            SqlParameter[] p = new SqlParameter[5];
			p[0] = new SqlParameter("@PK_iTrangslideID", entity.PK_iTrangslideID);
            p[1] = new SqlParameter("@FK_iSlideID", entity.FK_iSlideID);
            p[2] = new SqlParameter("@iSothutu", entity.iSothutu);
			p[3] = new SqlParameter("@sTieude", entity.sTieude);
			p[4] = new SqlParameter("@sGhichu", entity.sGhichu);
            return p;
        }
        #endregion
       
    }
}